#
# @lc app=leetcode.cn id=1413 lang=python
#
# [1413] 逐步求和得到正数的最小值
#

# @lc code=start
class Solution(object):
    def minStartValue(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        start = 1
        total=0
        min_total=0
        for num in nums:
            total+=num
            # 计算最小的累加和，最小的累加和要大于1就行
            min_total=min(min_total,total)
            # 如果最小的累加和小于等于1，说明当前的累加和都小于等于1，需要增加start
            start=max(start,1-min_total)
        return start
# @lc code=end

